home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-12 | 4.1 KB | 108 lines | [TEXT/CCL2] |
- ;
- ; think-ref-lookup.lisp
- ;
- ; This code enables you to lookup THINK Reference (TM) from Fred editor.
- ; If you load this file, the lookup function ed-think-reference is bound to m-r.
- ;
- ; The original code is posted to info-mcl@cambridge.apple.com on 12/1/1993
- ; by Jeffrey B Kane (jbk@world.std.com).
- ; I added some faculties
- ; * to launch THINK Reference (TM) if you have not loaded it yet.
- ; * to get the current S expression and lookup if it is a symbol.
- ; * to handle appleevent-error and display its message to mini-buffer.
- ;
- ; And on Bill St. Clair's (bill@cambridge.apple.com) advice, I changed my code
- ; to search THINK Reference (TM) with _PBDTGetAPPL. I referd to his code
- ; in the file cambridge.apple.com /pub/mcl2/contrib/processes.lisp.
- ;
- ; Special thanks for Jeffery and Bill.
- ;
- ; Masaya UEDA ueda@shpcsl.sharp.co.jp
-
- (eval-when (:compile-toplevel :execute :load-toplevel)
- (require :appleevent-toolkit))
-
- (defun %get-creator-path (creator fsspec)
- (let ((devs (directory "*:")))
- (dolist (vrefnum (sort (mapcar 'volume-number devs) #'>))
- (rlet ((pb :DTPBRec
- :ioNamePtr (%null-ptr)
- :ioVRefnum vrefnum))
- (when (= (#_PBDTGetPath pb) #$noErr)
- (setf (rref pb :DTPBRec.ioNamePtr)
- (%inc-ptr fsspec (get-field-offset :fsspec.name))
- (pref pb :DTPBRec.ioIndex) 0
- (pref pb :DTPBRec.ioFileCreator) creator)
- (when (= (#_PBDTGetAPPL pb) #$noErr)
- (setf (pref fsspec :fsspec.vRefnum) vrefnum
- (pref fsspec :fsspec.parID) (pref pb :DTPBRec.ioAPPLParID))
- (return (values))))))))
-
- #|
- (defun get-creator-path (creator)
- (rlet ((fsspec :fsspec))
- (%get-creator-path creator fsspec)
- (%path-from-fsspec fsspec)))
- |#
-
- (defun %launch-application (fsspec)
- (rlet ((lpb :LaunchParamBlockRec
- :launchBlockID #$extendedBlock
- :launchEPBLength #$extendedBlockLen
- :launchFileFlags 0
- :launchControlFlags (+ #$launchContinue #$launchNoFileFlags)
- :launchAppSpec fsspec
- :launchAppParameters (%null-ptr)))
- (if (= (#_LaunchApplication lpb) #$noErr)
- (values (rref lpb :LaunchParamBlockRec.launchProcessSN.highLongOfPSN)
- (rref lpb :LaunchParamBlockRec.launchProcessSN.LowLongOfPSN)))))
-
- #|
- (defun launch-application (filename &aux (pf (probe-file filename)))
- (if pf (rlet ((fsspec :fsspec))
- (with-pstrs ((name (mac-namestring pf)))
- (#_FSMakeFSSpec 0 0 name fsspec))
- (%launch-application fsspec))))
- |#
-
- (defun think-reference (search-string)
- (with-aedescs (ae target reply)
- (with-pstrs ((pstring search-string))
- (multiple-value-bind (psnhigh psnlow) (find-process-with-signature :|DanR|)
- (unless psnhigh
- (multiple-value-setq (psnhigh psnlow)
- (rlet ((fsspec :fsspec))
- (%get-creator-path :|DanR| fsspec)
- (%launch-application fsspec))))
- (when psnhigh
- (create-psn-target target psnhigh psnlow)
- ;; create an apple event
- (ae-error (#_AECreateAppleEvent
- :|DanR|
- :|REF |
- target
- #$kAutoGenerateReturnID
- #$kAnyTransactionID
- ae))
- ;; stuff it with our parameters
- (ae-error (#_AEPutParamPtr
- ae
- #$keyDirectObject
- #$typeChar
- (%inc-ptr pstring)
- (%get-unsigned-byte pstring)))
- ;; send it off
- (send-appleevent ae reply :reply-mode :wait-reply))))))
-
- (defmethod ed-think-reference ((fm fred-mixin))
- (let ((sym (ed-current-sexp fm)))
- (when (and sym (symbolp sym))
- (let ((sn (symbol-name sym)))
- (when (or (char= #\_ (char sn 0)) (char= #\$ (char sn 0)))
- (setq sn (subseq sn 1)))
- (handler-case (think-reference sn)
- (appleevent-error (condition)
- (format (view-mini-buffer fm) "~a: ~a"
- sn condition)))))))
-
- (def-fred-command (:meta #\r) ed-think-reference)